<template>
  <div class="app-container">
    <el-row :gutter="10">
      <el-col :span="12">
        <el-card style="height: 792px">
          <el-row :gutter="10">
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"

              >新增无电子档案工程
              </el-button>
              <!--              v-hasPermi="['system:gongcheng:add']"-->
            </el-col>
            <!--            <el-col :span="1.5">-->
            <!--              <el-button-->
            <!--                type="success"-->
            <!--                plain-->
            <!--                icon="el-icon-edit"-->
            <!--                size="mini"-->
            <!--                :disabled="single"-->
            <!--                @click="handleUpdate"-->
            <!--                v-hasPermi="['system:gongcheng:edit']"-->
            <!--              >修改信息</el-button>-->
            <!--            </el-col>-->
            <!--            <el-col :span="1.5">-->
            <!--              <el-button-->
            <!--                type="danger"-->
            <!--                plain-->
            <!--                icon="el-icon-delete"-->
            <!--                size="mini"-->
            <!--                :disabled="multiple"-->
            <!--                @click="handleDelete"-->
            <!--                v-hasPermi="['system:gongcheng:remove']"-->
            <!--              >删除</el-button>-->
            <!--            </el-col>-->
            <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-check"
                size="mini"
                :disabled="single"
                @click="judge"
              >工程归档
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-upload2"
                size="mini"
                @click="handleImport"
              >导入工程
              </el-button>
            </el-col>
            <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true"
                     style="float:right;">
              <el-form-item label="工程名称" prop="engName">
                <el-input
                  v-model="queryParams.engName"
                  placeholder="请输入工程名称"
                  clearable
                  @keyup.enter.native="handleQuery"
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-row>
          <el-table v-loading="loading"
                    :row-style="{height: '10px'}" :data="gongchengList" ref="singleTable" highlight-current-row
                    @current-change="handleCurrentChange" height="650">
            <!--            <el-table-column type="selection" width="55" align="center" />-->
            <el-table-column label="" width="60">
              <template slot-scope="{ $index }">
                {{ $index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="工程名称" width="300" align="center" prop="engName"/>
            <el-table-column label="案卷数" width="80" align="center" prop="anJuanShu"/>
            <el-table-column label="已录卷数" width="80" align="center" prop="yuliuA"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"

                >修改
                </el-button>
                <!--                v-hasPermi="['system:gongcheng:edit']"-->
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"

                >删除
                </el-button>
                <!--                v-hasPermi="['system:gongcheng:remove']"-->
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card style="height: 792px">
          <entityAnjuan @transport="changeShow" @addAnjuan="addAnjuanNumber" :parentData="parentData" :ifDel="ifDelete"
                        :mergeTime="mergeAnjuan"/>
        </el-card>
      </el-col>
    </el-row>
    <el-row style="margin-top: 8px">
      <el-card>
        <div v-if="ifShow">
          <span style="font-size: 18px;font-weight: bolder;color: #5087cc">工程信息：</span>
          <el-form @submit.native.prevent :label-position="labelPosition" style="margin-top: 8px" ref="form"
                   :model="form" label-width="90px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="工程名称" prop="engName">
                  <el-input class="custom-input" style="width: 750px" v-model="form.engName"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="档案馆名称" prop="dangAnGuanName">
                  <el-input class="custom-input" v-model="form.dangAnGuanName"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="档案馆代号" prop="dangAnGuanNo">
                  <el-input class="custom-input" v-model="form.dangAnGuanNo"/>
                </el-form-item>
                <el-form-item label="全宗号" prop="quanZongNo">
                  <el-input class="custom-input" v-model="form.quanZongNo"/>
                </el-form-item>
                <el-form-item label="密级" prop="secretLevel">
                  <el-select class="custom-input" v-model="form.secretLevel">
                    <el-option
                      v-for="dict in dict.type.security_eng"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="保存年限" prop="storageLife">
                  <el-select v-model="form.storageLife">
                    <el-option
                      v-for="dict in dict.type.save_dict"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="案卷数" prop="anJuanShu">
                  <el-input style="width: 300px" v-model="form.anJuanShu"/>
                </el-form-item>
                <el-form-item label="形成年度" prop="xingChengNianDu">
                  <el-input style="width: 300px" v-model="form.xingChengNianDu"/>
                </el-form-item>

              </el-col>

              <el-col :span="6">
                <el-form-item style="margin-left: -10px" label="开工日期" prop="bianZhiDateStart">
                  <el-date-picker clearable
                                  v-model="form.bianZhiDateStart"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  style="margin-right: 10px"
                  >
                  </el-date-picker>
                </el-form-item>
                <el-form-item style="margin-left: -10px" label="投资金额" prop="engCost">
                  <el-input style="width: 260px" v-model="form.engCost"/>
                  （万元）
                </el-form-item>


                <el-form-item style="margin-left: -10px" label="移交单位" prop="yiJiaoDanWei">
                  <el-input v-model="form.yiJiaoDanWei"/>
                </el-form-item>

              </el-col>
              <el-col :span="6">
                <el-form-item label="竣工日期" prop="bianZhiDateEnd">
                  <el-date-picker clearable
                                  v-model="form.bianZhiDateEnd"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                  >
                  </el-date-picker>
                </el-form-item>

                <el-form-item label="工程地址" prop="engAddress">
                  <el-input v-model="form.engAddress"/>
                </el-form-item>
                <el-form-item label="备注" prop="beiZhu">
                  <el-input v-model="form.beiZhu"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div v-else-if="anjuanShow">
          <span style="font-size: 18px;font-weight: bolder;color: #5087cc">案卷信息：</span>
          <el-form @submit.native.prevent ref="form" :label-position="labelPosition" :model="anjuanform"
                   label-width="100px" style="margin-top: 8px">
            <el-row :gutter="20">
              <el-form-item label="案卷题名" prop="anJuanName" style="margin-left: 0.5%">
                <el-input v-model="anjuanform.anJuanName" placeholder="请输入案卷题名"/>
              </el-form-item>
              <el-col :span="6">
                <el-form-item label="案卷号" prop="anJuanNo">
                  <el-input v-model="anjuanform.anJuanNo" placeholder="案卷号"/>
                </el-form-item>
                <el-form-item label="编制单位" prop="xingChengDanWei">
                  <el-input v-model="anjuanform.xingChengDanWei" placeholder="形成单位"/>
                </el-form-item>
                <el-form-item label="库号" prop="kuNum">
                  <el-input v-model="anjuanform.kuNum" placeholder="库号"/>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <!--            第二列-->
                <el-form-item label="总卷号" prop="zongJuanNo">
                  <el-input v-model="anjuanform.zongJuanNo" placeholder="总卷号"/>
                </el-form-item>
                <el-form-item label="兰图张数" prop="lanTuZhangShu">
                  <el-input v-model="anjuanform.lanTuZhangShu" placeholder="兰图张数"/>
                </el-form-item>
                <el-form-item label="列号" prop="leiNum">
                  <el-input v-model="anjuanform.leiNum" placeholder="列号"/>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <!--            第三列-->
                <el-form-item label="档号" prop="dangNo">
                  <el-input v-model="anjuanform.dangNo" placeholder="档号"/>
                </el-form-item>
                <el-form-item label="底图张数" prop="diTuZhangShu">
                  <el-input v-model="anjuanform.diTuZhangShu" placeholder="底图张数"/>
                </el-form-item>
                <el-form-item label="架号" prop="jiaNum">
                  <el-input v-model="anjuanform.jiaNum" placeholder="架号"/>
                </el-form-item>

              </el-col>
              <el-col :span="6">
                <!--            第四列-->
                <el-form-item label="卷标" prop="juanNo">
                  <el-input v-model="anjuanform.juanNo" placeholder="卷标"/>
                </el-form-item>
                <el-form-item label="文字材料张数" prop="wenZiCaiLiaoZhangShu">
                  <el-input v-model="anjuanform.wenZiCaiLiaoZhangShu" placeholder="文字材料张数"/>
                </el-form-item>
                <el-form-item label="层数" prop="cengShu">
                  <el-input v-model="anjuanform.cengShu" placeholder="层数"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div v-else>
          <el-empty style="margin-top: -30px" description="未选择信息"></el-empty>
        </div>
      </el-card>
    </el-row>
    <!-- 添加或修改实体工程信息表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form @submit.native.prevent ref="form" :model="form" :rules="rules" label-width="90px">
        <!--        <el-form-item label="电子工程id" prop="eid">-->
        <!--          <el-input v-model="form.eid" placeholder="请输入电子工程id" />-->
        <!--        </el-form-item>-->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="工程名称" prop="engName">
              <el-input v-model="form.engName" placeholder="请输入工程名称"/>
            </el-form-item>
            <el-form-item label="档案馆名称" prop="dangAnGuanName">
              <el-input v-model="form.dangAnGuanName" placeholder="请输入档案馆名称"/>
            </el-form-item>
            <el-form-item label="档案馆代号" prop="dangAnGuanNo">
              <el-input v-model="form.dangAnGuanNo" placeholder="请输入档案馆代号"/>
            </el-form-item>
            <el-form-item label="全宗号" prop="quanZongNo">
              <el-input v-model="form.quanZongNo" placeholder="请输入全宗号"/>
            </el-form-item>
            <div style="display: flex; align-items: center;margin-left: 10px">
              <span style="color: red;margin-right: -15px;margin-top: -20px">*</span>
              <el-form-item label="分类名称">
                <el-cascader
                  style="width: 380px;"
                  clearable
                  v-model="fenLei"
                  placeholder="请选择分类"
                  :options="daflglList"
                  :props="{ label: 'name', value: 'no' , emitPath:false}"
                  filterable
                ></el-cascader>
              </el-form-item>
            </div>
            <el-form-item label="密级" prop="secretLevel">
              <el-select v-model="form.secretLevel" placeholder="请选择密级">
                <el-option
                  v-for="dict in dict.type.security_eng"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="保存年限" prop="storageLife">
              <el-select v-model="form.storageLife" placeholder="请选择保存年限">
                <el-option
                  v-for="dict in dict.type.save_dict"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="案卷数" prop="anJuanShu">
              <el-input v-model="form.anJuanShu" placeholder="请输入案卷数"/>
            </el-form-item>
          </el-col>


          <el-col :span="12">

            <el-form-item label="开工日期" prop="bianZhiDateStart">
              <el-date-picker clearable
                              v-model="form.bianZhiDateStart"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择开工日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="竣工日期" prop="bianZhiDateEnd">
              <el-date-picker clearable
                              v-model="form.bianZhiDateEnd"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择竣工日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="形成年度" prop="xingChengNianDu">
              <el-input v-model="form.xingChengNianDu" :maxlength="4" placeholder="请输入形成年度"/>
            </el-form-item>
            <el-form-item label="移交单位" prop="yiJiaoDanWei">
              <el-input v-model="form.yiJiaoDanWei" placeholder="请输入移交单位"/>
            </el-form-item>
            <el-form-item label="投资金额" prop="engCost">
              <el-input style="width: 320px" v-model="form.engCost" placeholder="请输入投资金额"/>
              （万元）
            </el-form-item>
            <el-form-item label="工程地址" prop="engAddress">
              <el-input v-model="form.engAddress" placeholder="请输入工程地址"/>
            </el-form-item>
            <el-form-item label="备注" prop="beiZhu">
              <el-input v-model="form.beiZhu" placeholder="请输入备注"/>
            </el-form-item>
          </el-col>


          <!--        <el-form-item label="大类" prop="daLeiName">-->
          <!--          <el-input v-model="form.daLeiName" placeholder="请输入大类" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="大类" prop="daLeiNo">-->
          <!--          <el-input v-model="form.daLeiNo" placeholder="请输入大类" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="属类" prop="shuLeiName">-->
          <!--          <el-input v-model="form.shuLeiName" placeholder="请输入属类" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="属类" prop="shuLeiNo">-->
          <!--          <el-input v-model="form.shuLeiNo" placeholder="请输入属类" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="小类" prop="xiaoLeiName">-->
          <!--          <el-input v-model="form.xiaoLeiName" placeholder="请输入小类" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="小类" prop="xiaoLeiNo">-->
          <!--          <el-input v-model="form.xiaoLeiNo" placeholder="请输入小类" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="电子工程编号" prop="engNo">-->
          <!--          <el-input v-model="form.engNo" placeholder="请输入电子工程编号" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="编制单位" prop="bianZhiDanWei">-->
          <!--          <el-input v-model="form.bianZhiDanWei" placeholder="请输入编制单位" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="${comment}" prop="shuZiHuaDanWei">-->
          <!--          <el-input v-model="form.shuZiHuaDanWei" placeholder="请输入${comment}" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="归档时间" prop="guiDangTime">-->
          <!--          <el-date-picker clearable-->
          <!--            v-model="form.guiDangTime"-->
          <!--            type="date"-->
          <!--            value-format="yyyy-MM-dd"-->
          <!--            placeholder="请选择归档时间">-->
          <!--          </el-date-picker>-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="${comment}" prop="yuliuA">-->
          <!--          <el-input v-model="form.yuliuA" placeholder="请输入${comment}" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="${comment}" prop="yuliuB">-->
          <!--          <el-input v-model="form.yuliuB" placeholder="请输入${comment}" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="${comment}" prop="yuliuC">-->
          <!--          <el-date-picker clearable-->
          <!--            v-model="form.yuliuC"-->
          <!--            type="date"-->
          <!--            value-format="yyyy-MM-dd"-->
          <!--            placeholder="请选择${comment}">-->
          <!--          </el-date-picker>-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="创建时间" prop="creationTime">-->
          <!--          <el-date-picker clearable-->
          <!--            v-model="form.creationTime"-->
          <!--            type="date"-->
          <!--            value-format="yyyy-MM-dd"-->
          <!--            placeholder="请选择创建时间">-->
          <!--          </el-date-picker>-->
          <!--        </el-form-item>-->
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入工程对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="700px" append-to-body :destroy-on-close="true">
      <div style="margin-left: 50px">
        <el-upload
          ref="upload"
          :limit="1"
          :headers="upload.headers"
          :action="upload.url + '?classId=' + upload.classId"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
          style="margin-left: 100px"
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        </el-upload>
        <el-button type="success" @click="getTemplate()" style="margin-left:510px;margin-top: 5px;">下载模版</el-button>
      </div>
      <div style="font-weight: bold">分类名称：</div>
      <class-cascader ref="classCascader" style="display: flex; justify-content: center; align-items: center;margin-top: 10px;margin-bottom: -10px" @child-value-change="setUploadClass"></class-cascader>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="CheckSubmit">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import {noMergerListGongcheng, getGongcheng, delGongcheng, addGongcheng, updateGongcheng, getTemplate} from "@/api/system/gongcheng";
import moment from 'moment';
import entityAnjuan from "./entityAnjuan";
import {listDaflgl} from "@/api/system/daflgl";
import {v4 as uuidv4} from 'uuid';
import {getToken} from "@/utils/auth";
import classCascader from "@/views/system/shiti_receive/classCascader.vue";
import {listAnjuan, updateAnjuan} from "@/api/system/shiti_anjuan";

export default {
  name: "Gongcheng",
  dicts: ['security_eng', 'save_dict'],
  components: {
    classCascader,
    entityAnjuan,
  },
  data() {
    return {
      fenLei: null,
      daflglList: [],
      editList:[],
      categoryMap: {}, // 分类ID与名称的映射
      anjuanShow: false,
      mergeAnjuan: 0,
      labelPosition: 'left',
      ifShow: false,
      currentRow: null,
      // 遮罩层
      loading: true,
      // 选中数组
      id: null,
      parentData: null,
      ifDelete: 0,
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实体工程信息表表格数据
      gongchengList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        eid: null,
        engName: null,
        dangAnGuanName: null,
        dangAnGuanNo: null,
        quanZongNo: null,
        daLeiName: null,
        daLeiNo: null,
        shuLeiName: null,
        shuLeiNo: null,
        xiaoLeiName: null,
        xiaoLeiNo: null,
        xingChengNianDu: null,
        storageLife: null,
        secretLevel: null,
        engNo: null,
        yiJiaoDanWei: null,
        bianZhiDanWei: null,
        shuZiHuaDanWei: null,
        bianZhiDateStart: null,
        bianZhiDateEnd: null,
        engAddress: null,
        engCost: null,
        guiDangTime: null,
        beiZhu: null,
        anJuanShu: null,
        projectStatus: null,
        bindStatus: null,
        yuliuA: null,
        yuliuB: null,
        yuliuC: null,
        creationTime: null
      },

      // 上传文件列表
      uploadedFiles: [],
      // 导入弹窗
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 档案分类
        classId: 0,
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/gongcheng/importGCExcel"
      },

      // 表单参数
      form: {},
      judgeForm: {},
      anjuanform: {},
      // 表单校验
      rules: {
        engName: [
          {required: true, message: "工程名称不能为空", trigger: "blur"}
        ],
        dangAnGuanName: [
          {required: true, message: "档案馆名称不能为空", trigger: "blur"}
        ],
        dangAnGuanNo: [
          {required: true, message: "档案馆代号不能为空", trigger: "blur"}
        ],
        quanZongNo: [
          {required: true, message: "全宗号不能为空", trigger: "blur"}
        ],
        secretLevel: [
          {required: true, message: "密级不能为空", trigger: "blur"}
        ],
        storageLife: [
          {required: true, message: "保存期限不能为空", trigger: "blur"}
        ],
        anJuanShu: [
          {required: true, message: "案卷数不能为空", trigger: "blur"}
        ],
        bianZhiDateStart: [
          {required: true, message: "开工日期不能为空", trigger: "blur"}
        ],
        bianZhiDateEnd: [
          {required: true, message: "竣工日期不能为空", trigger: "blur"}
        ],
        xingChengNianDu: [
          {required: true, message: "形成年度不能为空", trigger: "blur"}
        ],
        yiJiaoDanWei: [
          {required: true, message: "移交单位不能为空", trigger: "blur"}
        ],
        // engCost:[
        //   { required: true, message: "投资金额不能为空", trigger: "blur" }
        // ],
        engAddress: [
          {required: true, message: "工程地址不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getdaflList().then(() => {
      this.getList();
    });
  },
  methods: {
    async updateSerialNumber() {
      await noMergerListGongcheng().then(response => {
        this.editList = response.rows;
        const rowIndex = this.editList.indexOf(this.parentData);
        // 获取当前行之后的行的数据
        const rowsAfterCurrent = this.editList.slice(rowIndex + 1);
        for (let j = 0; j < rowsAfterCurrent.length; j++) {
          let query = {gid: rowsAfterCurrent[j].id};
          listAnjuan(query).then(res => {
            let allId = res.rows.map(row => row.id);
            let allZjh = res.rows.map(row => row.zongJuanNo);
            for (let i = 0; i < allId.length; i++) {
              // let dn = this.parentData.xingChengNianDu + '-' + this.currentRow.fenLeiNo + '-' + this.currentRow.storageLife + '-' + ajn;
              const myQuery = {id: allId[i], zongJuanNo: allZjh[i] - this.parentData.yuliuA};
              updateAnjuan(myQuery);
            }
            if (this.parentData.daLeiNo === rowsAfterCurrent[j].daLeiNo && this.parentData.shuLeiNo === rowsAfterCurrent[j].shuLeiNo && this.parentData.xiaoLeiNo === rowsAfterCurrent[j].xiaoLeiNo) {
              let allAjh = res.rows.map(row => row.anJuanNo);
              let allFlh = res.rows.map(row => row.fenLeiNo);
              for (let i = 0; i < allId.length; i++) {
                console.log(this.parentData)
                let anJuanHao = allAjh[i]-this.parentData.yuliuA
                let dn = rowsAfterCurrent[j].xingChengNianDu + '-' + allFlh[i] + '-' + rowsAfterCurrent[j].storageLife + '-' + anJuanHao;
                const myQuery = {id: allId[i], dangNo: dn, anJuanNo: anJuanHao};
                updateAnjuan(myQuery);
            }
            }
          });
        }
        this.$modal.msgSuccess("删除成功");
        this.getList()
      });
    },
    getTemplate(){
      getTemplate().then((response) => {
        const blob1 = new Blob([response], {type: "image/xlsx"});
        const link = document.createElement("a");
        link.href = URL.createObjectURL(blob1);
        link.download = "宝鸡市实体档案导入模版.xlsx";
        link.click();
      })
    },
    setUploadClass(value) {
      this.upload.classId = value;
    },
    /** 查询分类大纲列表 */
    getdaflList() {
      return new Promise((resolve, reject) => {
        listDaflgl().then(response => {
          this.daflglList = this.handleTree(response.data, "id", "fid");
          response.data.forEach(category => {
            this.categoryMap[category.no] = category.name;
          });
          // 在数据加载完成后调用 resolve 表示操作成功
          resolve();
        });
      })
    },
    getValue(inputKey) {
      this.result = this.categoryMap[inputKey];
      return this.result
    },
    /** 查询实体工程信息表列表 */
    getList() {
      this.loading = true;
      noMergerListGongcheng(this.queryParams).then(response => {
        this.gongchengList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        eid: null,
        engName: null,
        dangAnGuanName: "宝鸡市城建档案馆",
        dangAnGuanNo: 461403,
        quanZongNo: "CJDA",
        daLeiName: null,
        daLeiNo: null,
        shuLeiName: null,
        shuLeiNo: null,
        xiaoLeiName: null,
        xiaoLeiNo: null,
        xingChengNianDu: null,
        storageLife: null,
        secretLevel: null,
        engNo: null,
        yiJiaoDanWei: null,
        bianZhiDanWei: null,
        shuZiHuaDanWei: null,
        bianZhiDateStart: null,
        bianZhiDateEnd: null,
        engAddress: null,
        engCost: null,
        guiDangTime: null,
        beiZhu: null,
        anJuanShu: null,
        projectStatus: null,
        bindStatus: null,
        yuliuA: null,
        yuliuB: null,
        yuliuC: null,
        creationTime: null
      };
      this.resetForm("form");
    },
    //点击行触发，选中或不选中复选框
    handleCurrentChange(val) {
      this.currentRow = val;
      // this.ids = val.map(item => item.id)
      // this.single = val.length!==1
      // this.multiple = !val.length
      this.parentData = val
      this.single = false
      this.ids = []
      if (val != null) {
        this.ids.push(val.id);
        this.showData();
        this.anjuanShow = false;
        this.ifShow = true;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    addAnjuanNumber(data) {
      let nowId = this.parentData.id;
      let UpdateQuery = {id: nowId, yuliuA: data}
      updateGongcheng(UpdateQuery).then(response => {
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.fenLei = null;
      this.open = true;
      this.title = "添加实体工程信息表";
    },
    showData() {
      this.reset();
      const id = this.ids
      getGongcheng(id).then(response => {
        this.form = response.data;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGongcheng(id).then(response => {
        this.form = response.data;
        this.fenLei = this.form.daLeiNo + this.form.shuLeiNo + this.form.xiaoLeiNo;
      });
      this.open = true;
      this.title = "修改实体工程信息表";
    },
    judge(row) {
      const id = row.id || this.ids;
      getGongcheng(id).then(response => {
        this.JudgeForm = response.data;
        if (this.JudgeForm.anJuanShu === this.JudgeForm.yuliuA) {
          this.mergeEng(row)
        } else {
          this.$modal.msgError('该工程组卷未完成')
        }
      });
    },
    /** 工程归档函数 */
    mergeEng(row) {
      const id = row.id || this.ids; // 获取传递进来的 'id' 属性
      let time = moment().format('YYYY-MM-DD HH:mm:ss');
      let dataToUpdate = {
        id: id[0],
        projectStatus: 1, // 将 projectStatus 字段修改为 1
        bindStatus: 0,
        guiDangTime: time,
        shuZiHuaDanWei: '无'
      };
      this.mergeAnjuan += 1;
      updateGongcheng(dataToUpdate)
        .then(response => {
          this.$modal.msgSuccess("归档成功");
          this.getList(); // 更新列表数据
        })
        .catch(error => {
          console.error('更新失败:', error);
          // 在失败时进行适当的错误处理
        });
    },
    changeShow(data) {
      this.ifShow = false;
      this.anjuanform = data;
      this.anjuanform.dangNo = this.parentData.xingChengNianDu + '-' + this.anjuanform.fenLeiNo + '-' + this.anjuanform.storageLife + '-0' + this.anjuanform.anJuanNo;
      this.anjuanShow = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (this.fenLei === null) {
          this.$modal.msgError("请选择类别")
        } else {
          if (valid) {
            if (this.form.id != null) {
              this.form.daLeiNo = this.fenLei.charAt(0);
              this.form.shuLeiNo = this.fenLei.charAt(1);
              this.form.xiaoLeiNo = this.fenLei.slice(2);
              this.form.daLeiName = this.categoryMap[this.fenLei.charAt(0)];
              this.form.shuLeiName = this.categoryMap[this.fenLei.substring(0, 2)];
              this.form.xiaoLeiName = this.categoryMap[this.fenLei];
              updateGongcheng(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              this.form.id = uuidv4();
              this.form.projectStatus = 0;
              this.form.daLeiNo = this.fenLei.charAt(0);
              this.form.shuLeiNo = this.fenLei.charAt(1);
              this.form.xiaoLeiNo = this.fenLei.slice(2);
              this.form.creationTime = moment().format('YYYY-MM-DD HH:mm:ss');
              this.form.daLeiNo = this.fenLei.charAt(0);
              this.form.shuLeiNo = this.fenLei.charAt(1);
              this.form.xiaoLeiNo = this.fenLei.slice(2);
              this.form.daLeiName = this.categoryMap[this.fenLei.charAt(0)];
              this.form.shuLeiName = this.categoryMap[this.fenLei.substring(0, 2)];
              this.form.xiaoLeiName = this.categoryMap[this.fenLei];
              addGongcheng(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        }

      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该实体工程信息表').then(() => {
        this.ifDelete += 1;
        return delGongcheng(ids).then(() => {
          this.updateSerialNumber();
        });
      }).catch(() => {
      });
    },

    //文件上传前判断
    CheckSubmit() {
      let files = this.$refs.upload.uploadFiles;
      if (files.length === 0) {
        this.$modal.msgError("请上传档案文件！");
      } else if (this.upload.classId === 0) {
        this.$modal.msgError("请先选择分类！");
      } else {
        console.log(this.uploadedFiles);
        this.submitFileForm();
      }
    },

    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },

    /** 导入工程按钮操作 */
    handleImport() {
      this.upload.title = "导入工程";
      this.upload.open = true;
    },

    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },

    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }


  }
};
</script>

<style>
.el-form-item label {
  white-space: nowrap;
}

/* 使用自定义类 ".custom-input" 来控制输入框样式 */
.custom-input::before {
  content: none; /* 将星号内容设置为 "none"，这将隐藏星号 */
  margin-right: 0; /* 可选：将星号前面的间距设置为0 */
}
</style>
